﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>第三方设置</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Manage_Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>

    <script>
        $(function () {
            initTable();
        });

        //初始化表格  
        function initTable() {
            $('#load').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                striped: true,
                url: '/WaltSet/getgrid',
                sortName: 'WaltID',
                sortOrder: 'asc',
                border: true,
                remoteSort: false,
                idField: 'WaltID',
                pageSize: 20,
                singleSelect: true,
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'WaltID', title: '钱包ID', width: 100, sortable: true, align: 'center', hidden: true },
					{ field: 'WaltName', title: '钱包名称', width: 100, sortable: true, align: 'center' },
                    { field: 'PayName', title: "第三方支付类型", width: 150, align: 'center' },
                    { field: 'MapUsing', title: "应用范围", width: 150, align: 'center' },
                    { field: 'WaltMax', title: "钱包最大上限金额", width: 150, align: 'center' },
                ]],
                toolbar: '#tb'

            });
        }

        //添加上架信息对话框
        function AddDialog() {
            $('#DetailDialog').dialog('open').dialog('setTitle', '新增钱包');
            BindThirdPartyPayment("");
            BindUser();
            BindMerchants("");
            ClearText();
            document.getElementById("ok").style.display = "block";
        }

        //修改上架信息对话框
        function UpdateDialog() {
            var UpdateInfoID = $("#load").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#DetailDialog").dialog("open").dialog("setTitle", "修改钱包信息");
                document.getElementById("ok").style.display = "block";
                BindThirdPartyPayment(UpdateInfoID[0].WaltRec);
                BindUser();
                BindMerchants(UpdateInfoID[0].WaltMer);
                BingDetail();
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //查看详细窗口
        function OpenDetail() {
            var UpdateID = $("#load").datagrid("getSelections");
            if (UpdateID.length == 1) {
                $("#DetailDialog").dialog("open").dialog("setTitle", "钱包详细信息");
                document.getElementById("ok").style.display = "none";
                BindThirdPartyPayment(UpdateID[0].WaltRec);
                BindUser();
                BindMerchants(UpdateID[0].WaltMer);
                BingDetail();
            }
            else {
                $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateID.length + "</font>行");
            }
        }

        //
        function DeleteDialog() {
            //首先获取选中的上架信息的所有信息
            var checkdata = $("#load").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#load").datagrid("getSelections")[0];//获取整行数据
              
                var postdata = {
                    WaltID: checkdata.WaltID,
                    WaltName: checkdata.WaltName,
                    WaltDep: checkdata.WaltDep,
                    WaltMer: checkdata.WaltMer,
                    WaltUsing: checkdata.WaltUsing,
                    WaltRec: checkdata.WaltRec,
                    WaltMax: checkdata.WaltMax,
                    WaltLastTime: checkdata.WaltLastTime,
                    WaltLastOper: checkdata.WaltLastOper,
                    WaltState: checkdata.WaltState,
                };
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + "</font>该个钱包吗？", function (ok) {
                    if (ok) {
                        $.post("/WaltSet/SetOrderWalt?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                initTable();
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }
            else {
                $.messager.alert("友情提示", "每次只能删除一行数据，你已经选择了<font color='red' size='6'>" + checkdata.length + "</font>行");
            }
        }

        //保存
        function submitForm() {
            //alert("保存");
            var waltid = $("#WaltID").textbox('getValue');
            var waltname = $("#WaltName").textbox('getValue');
            //var waltmer = $("#WaltMer").textbox('getValue');
            var waltmer = $("#WaltMer").combobox('getValues').join(',');
            var waltrec = $("#WaltRec").combobox('getValue');
            var waltmax = $("#WaltMax").textbox('getValue');
            var waltdep = $("#WaltDep").combobox('getValue');
            //alert(waltdep);
            //var waltdep = $("#WaltDep").textbox('getValue');

            var cb_cz = document.getElementById("cb_cz");
            var cb_xf = document.getElementById("cb_xf");
            var cb_tx = document.getElementById("cb_tx");
            var cb_zy = document.getElementById("cb_zy");

            var waltusing = '';
            if (cb_cz.checked == true) {
                waltusing += '1';
            }
            else {
                waltusing += '0';
            }
            if (cb_xf.checked == true) {
                waltusing += '1';
            }
            else {
                waltusing += '0';
            }
            if (cb_tx.checked == true) {
                waltusing += '1';
            }
            else {
                waltusing += '0';
            }
            if (cb_zy.checked == true) {
                waltusing += '1';
            }
            else {
                waltusing += '0';
            }

            if (waltmax < 0) {
                $.messager.alert("友情提示", "钱包上限不为负数");
            }
            else
            {
                var postdata = {
                    WaltID: waltid,
                    WaltName: waltname,
                    WaltDep: waltdep,
                    WaltMer: waltmer,
                    WaltUsing: waltusing,
                    WaltRec: waltrec,
                    WaltMax: waltmax,
                    WaltLastTime: '',
                    WaltLastOper: 0,
                    WaltState: 1,
                };
                //首先判断前台的验证是否通过
                if (postdata.WaltName != "-1" & postdata.WaltDep != "" & postdata.WaltMer != "" & postdata.WaltRec != "" & postdata.WaltMax != "") {
                    var Tag = 0;
                    if (postdata.WaltID == "") {
                        Tag = 1;
                    }
                    else {
                        Tag = 2;
                    }
                    //使用异步实现修改用户信息
                    $.post("/WaltSet/SetOrderWalt?Tag=" + Tag, postdata, function (date) {
                        if (date == "1") {
                            $("#DetailDialog").dialog('close');
                            $("#load").datagrid('reload');
                            $.messager.alert("友情提示", "更新成功");
                        }
                        else if (date == "2") {
                            $("#DetailDialog").dialog('close');
                            $("#load").datagrid('reload');
                            //$.messager.alert("友情提示", "该钱包名已存在");
                        }
                        else if(date=="-1"){
                            $.messager.alert("友情提示", "修改失败，请检查");
                        }
                    });
                }
                else {
                    $.messager.alert("友情提示", "请填写必填选项");
                }

            }
           
        }

        //获取用户信息绑定
        function BingDetail() {
            var datas = $("#load").datagrid("getSelections")[0]; //获取选中行数据
            //alert(datas.WaltDep);
            $("#WaltID").textbox('setValue', datas.WaltID);
            $("#WaltName").textbox('setValue', datas.WaltName);
            $("#WaltDep").combotree('setValue', datas.WaltDep);
            $("#WaltMer").textbox('setValue', datas.WaltMer);
            $("#WaltRec").textbox('setValue', datas.WaltRec);
            $("#WaltMax").textbox('setValue', datas.WaltMax);

            var u = datas.WaltUsing;
            if (u.substr(0, 1) == '1') {
                var c = document.getElementById("cb_cz");
                c.checked = true;
            }
            else {
                var c = document.getElementById("cb_cz");
                c.checked = false;
            }

            if (u.substr(1, 1) == '1') {
                var c = document.getElementById("cb_xf");
                c.checked = true;
            }
            else {
                var c = document.getElementById("cb_xf");
                c.checked = false;
            }
            if (u.substr(2, 1) == '1') {
                var c = document.getElementById("cb_tx");
                c.checked = true;
            }
            else {
                var c = document.getElementById("cb_tx");
                c.checked = false;
            }
            if (u.substr(3, 1) == '1') {
                var c = document.getElementById("cb_zy");
                c.checked = true;
            }
            else {
                var c = document.getElementById("cb_zy");
                c.checked = false;
            }
        }

        //清空信息
        function ClearText() {
            //alert(0);
            $("#WaltID").textbox('setValue', "");
            $("#WaltName").textbox('setValue', "");
            $("#WaltDep").textbox('setValue', "");
            $("#WaltMer").textbox('setValue', "");
            $("#WaltRec").textbox('setValue', "");
            $("#WaltMax").textbox('setValue', "");
            document.getElementById("cb_cz").checked = false;
            document.getElementById("cb_xf").checked = false;
            document.getElementById("cb_tx").checked = false;
            document.getElementById("cb_zy").checked = false;
        }


        //绑定第三方支付
        function BindThirdPartyPayment(data) {
                $.get("/WaltSet/GetThridPay", {}, function (database) {
                    $('#WaltRec').combobox({
                        valueField: 'PayID',
                        textField: 'PayName',
                        value: data,
                        data: database
                    });
                })
        }
        //绑定用户范围
        function BindUser() {
            //$.get("/WaltSet/GetThridPay", {}, function (database) {
            //    $('#WaltDep').combobox({
            //        valueField: 'PayID',
            //        textField: 'PayName',
            //        data: database
            //    });
            //});
            $('#WaltDep').combotree({
                url: "/WaltSet/getDep",
                method: 'get',
                multiple: true
            });
        }
        //绑定商户范围
        function BindMerchants(tag) {
                $.get("/WaltSet/GetOrderMer", {}, function (database) {
                    $('#WaltMer').combobox({
                        valueField: 'MerID',
                        textField: 'MerName',
                        data: database,
                        value: tag,
                        multiple: true
                    });
                })
        }
    </script>

</head>
<body style="padding: 0;">
    <!--表格加载S-->
    <div>
        <table id="load" style="width: auto;"></table>
    </div>
    <!--表格加载E-->

    <!--工具栏S-->
    <div id="tb" style="padding: 5px; height: auto; width: 100%;">
        <div style="margin-bottom: 5px">
            <a href="#" class="easyui-linkbutton" id="btndetail" iconcls="icon-more" onclick="OpenDetail()" plain="true">明细</a>
            <a href="#" class="easyui-linkbutton" id="btnadd" iconcls="icon-add" onclick="AddDialog()" plain="true">新增</a>
            <a href="#" class="easyui-linkbutton" id="btnedit" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">编辑</a>
            <a href="#" class="easyui-linkbutton" id="btndell" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除</a>
            <hr style="margin-top: 5px" />
        </div>
    </div>
    <!--工具栏E-->

    <!--修改S-->
    <div id="DetailDialog" class="easyui-dialog" style="width: 550px; padding: 10px 0" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <table width="500px">
            <tr hidden="hidden">
                <td>
                    <input class="easyui-textbox" type="text" id="WaltID" name="WaltID" />
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">钱包名称：</td>
                <td style="padding: 10px">
                    <input class="easyui-textbox" id="WaltName" style="width: 200px; height: 24px" data-options="required:true" />
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">用户范围：</td>
                <td style="padding: 10px">
                    <input id="WaltDep" class="easyui-textbox" style="width: 200px; height: 24px" data-options="required:true">
                    @*<input id="btn_dep" type="button" value="选择" />*@
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">商户范围：</td>
                <td style="padding: 10px">
                    <input id="WaltMer" class="easyui-textbox" style="width: 200px; height: 24px" data-options="required:true">
                    @*<input id="btn_mer" type="button" value="选择" />*@
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">应用范围：</td>
                <td style="padding: 10px">
                    <label>
                        <input id="cb_cz" type="checkbox" value="" />充值
                    </label>
                    &nbsp;&nbsp;
                    <label>
                        <input id="cb_xf" type="checkbox" value="" />消费
                    </label>
                    &nbsp;&nbsp;
                    <label>
                        <input id="cb_tx" type="checkbox" value="" />提现
                    </label>
                    &nbsp;&nbsp;
                    <label>
                        <input id="cb_zy" type="checkbox" value="" />转移
                    </label>
                    &nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">第三方支付：</td>
                <td style="padding: 10px">
                    <input id="WaltRec" class="easyui-textbox" style="width: 200px; height: 24px">
                    @*<input id="btn_dep" type="button" value="选择" />*@
                </td>
            </tr>
            <tr>
                <td width="40%" align="right" style="padding: 10px">钱包上限：</td>
                <td style="padding: 10px">
                    <input id="WaltMax" class="easyui-textbox" style="width: 100px; height: 24px;" data-options="required:true">&nbsp;元
                </td>
            </tr>
        </table>
        <br />
        <br />
        <div id="ok" align="center" style="display: block">
            <a href="javascript:void(0)" id="submit" class="easyui-linkbutton" iconcls="icon-ok" onclick="submitForm()">保存</a> &nbsp;&nbsp;&nbsp;&nbsp;
            <a id="btnUpdateCancel" href="javascript:(0)" onclick="javascript:$('#DetailDialog').dialog('close')" class="easyui-linkbutton" data-options="iconCls:'icon-cancel'">取消</a>
        </div>
    </div>
    <!--修改E-->

</body>
</html>

